package cn.itsource.order.mapper;

import cn.itsource.order.domain.TOrderAddress;
import cn.itsource.order.domain.TOrderAdopt;
import org.apache.commons.lang3.time.DateUtils;
import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

public interface OrderAdoptMapper extends Mapper<TOrderAdopt> {
    default TOrderAdopt findByOrderSn(String out_trade_no){
        Example example = new Example(TOrderAdopt.class);
        example
                .createCriteria()
                .andEqualTo("orderSn",out_trade_no);
        return this.selectOneByExample(example);
    };

    default List<TOrderAdopt> findByStateAndTime(Date date){
        Example example = new Example(TOrderAdopt.class);
        example
                .createCriteria()
                .andEqualTo("state", 0)
                //时间在当前时间以及前十五分钟之间
                .andBetween("lastConfirmTime", DateUtils.addMinutes(new Date(), -60),date);
        return this.selectByExample(example);
    };
}
